package com.ruoyi.kaifa.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.kaifa.domain.vo.AUserVo;
import com.ruoyi.kaifa.utils.IpUtil;
import com.ruoyi.kaifa.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.kaifa.mapper.AUserMapper;
import com.ruoyi.kaifa.domain.AUser;
import com.ruoyi.kaifa.service.IAUserService;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-01
 */
@Service
public class AUserServiceImpl implements IAUserService 
{
    @Autowired
    private AUserMapper aUserMapper;

    /**
     * 查询用户
     * 
     * @param id 用户主键
     * @return 用户
     */
    @Override
    public AUser selectAUserById(Long id) {
        return aUserMapper.selectAUserById(id);
    }

    /**
     * 查询用户列表
     * 
     * @param aUser 用户
     * @return 用户
     */
    @Override
    public List<AUserVo> selectAUserList(AUser aUser) {
        return aUserMapper.selectAUserList(aUser);
    }

    /**
     * 新增用户
     * 
     * @param aUser 用户
     * @return 结果
     */
    @Override
    public int insertAUser(AUser aUser, HttpServletRequest request) {
        aUser.setId(SnowFlakeUtil.getFlowIdInstance().nextId());
        aUser.setCreateTime(DateUtils.getNowDate());
        aUser.setCreateIp(IpUtil.getIpByHttpServletRequest(request));
        return aUserMapper.insertAUser(aUser);
    }

    /**
     * 修改用户
     * 
     * @param aUser 用户
     * @return 结果
     */
    @Override
    public int updateAUser(AUser aUser, HttpServletRequest request) {
        aUser.setUpdateTime(new Date());
        aUser.setUpdateIp(IpUtil.getIpByHttpServletRequest(request));
        return aUserMapper.updateAUser(aUser);
    }

    /**
     * 批量删除用户
     * 
     * @param ids 需要删除的用户主键
     * @return 结果
     */
    @Override
    public int deleteAUserByIds(Long[] ids) {
        return aUserMapper.deleteAUserByIds(ids);
    }

    /**
     * 删除用户信息
     * 
     * @param id 用户主键
     * @return 结果
     */
    @Override
    public int deleteAUserById(Long id) {
        return aUserMapper.deleteAUserById(id);
    }


    @Override
    public AUser doLogin(AUser aUser) {
        return aUserMapper.getAUserByPhoneAndPassword(aUser);
    }
}
